var addTwoNumbers = function (l1, l2) {
    let head = new ListNode();
    head = l2;
    let num = 0;
    while (l1 && l2) {
        l2.val = l2.val + l1.val + num;
        if (l2.val > 9) {
            num = l2.value - 9;
            l2.val = 9;
        }
        if (!l1.next && l2.next) {
            let new_node = new ListNode();
            new_node.val = 0;
            new_node.next = null;
            l1.next = new_node;
        } else {
            l1 = l1.next;
        }
        if (!l2.next && l1.next) {
            let new_node = new ListNode();
            new_node.val = 0;
            new_node.next = null;
            l2.next = new_node;
        } else {
            l2 = l2.next;
        }
    }
    return head;

};

function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}
// 测试用例
let l1 = new ListNode(2);
l1.next = new ListNode(4);
l1.next.next = new ListNode(3);

let l2 = new ListNode(5);
l2.next = new ListNode(6);
l2.next.next = new ListNode(4);

let r = addTwoNumbers(l1, l2);

while (r) {
    console.log(r.val);
    r = r.next;
}